<?php
namespace Home\Controller;
use Home\Service\DailyDataGather;
use Common\Lib\User;

class DailyDataStatisticController extends CommonController{
    protected $table = "";
    protected $pageSize = 30;
    protected $d = null;

    private function getObjType(){
        $roleEname =  I('get.objType', $this->getRoleEname()) ;
        $map = array(
                     
                     'hrMaster'=> 'Departments',
                     'Departments'=>'Users',  //点击部门进入人事专员页面
                     'humanResource' => 'SingleUser',
                     'captain' => 'Users'
                    );

        if (isset($map[$roleEname])) {
            return $map[$roleEname];
        } else {
            return 'SingleUser';
        }
    }


    public function index(){
        
        $this->assign('objType', $this->getObjType());
        $this->assign('start', I('get.start',''));
        $this->assign('end',   I('get.end',''));
        $this->display();
    }

  /*  public function getList(){
        $this->d =   new DailyDataGather;
        $start = I('get.start');
        $end = I('get.end');
        $department_id = session('account')['userInfo']['department_id'];
        $role_id = session('account')['userInfo']['role_id'];
        $sort_field = I('get.sort_field', 'id');
        $sort_order = I('get.sort_order', 'asc');
        $sort_field = empty($sort_field) ? 'id' :$sort_field;
        $sort_order = empty($sort_order) ? 'asc' :$sort_order;
        $list = $this->d->getDepartment($start,$end,$department_id,$role_id,$sort_field,$sort_order);
        $result = array('list'=>$list, 'count'=>count($list));
        $this->ajaxReturn($result);
    }*/
    /*重新更改 开始*/
     public function getList(){
        $this->d =   new DailyDataGather;
         $this->setServiceQuery();
        $list = $this->setQeuryCondition();
        $result = array('list'=>$list, 'count'=>count($list));
        $this->ajaxReturn($result);
    }
    private function setServiceQuery(){
        $sort_field = I('get.sort_field', 'id');
        $sort_order = I('get.sort_order', 'asc');
        $sort_field = empty($sort_field) ? 'id' :$sort_field;
        $this->d
             ->setDate(I('get.start'), I('get.end'))
             ->setOrder($sort_field." ".$sort_order);
    }
    public function setQeuryCondition(){
        return $this->setCondition();
    }
    private function setCondition(){
        $this->roleEname = $this->getRoleEname();
        $funcName = $this->roleEname."Condition";

        if (method_exists($this, $funcName)) {
            return call_user_func(array($this, $funcName));
        }
        return array(); 
    }
    //判断用户角色
    private function hrMasterCondition(){
        $objType =  I('get.objType');
        $id = I('get.id', 0);
        if ($id==0) {
            return $this->getDepartments();
        } else {
            return call_user_func(array($this, "get".$objType),  $id);
        }
    }

      private function getDepartments(){
        return $this->d->getDepartment();
    }

     private function DepartmentsCondition(){
        return $this->getUsers(session('account')['userInfo']['department_id']);
    }
      private function getUsers($department_id){
        return $this->d->getUsers($department_id);
    }
    //个人的每日数据统计(非人事经理)
    private function humanResourceCondition(){
        $objType =  I('get.objType');
        $id = I('get.id', 0);
        if ($id==0) {
            return $this->getSingleUser(session('account')['userInfo']['user_id']);
        } else {
            return call_user_func(array($this, "get".$objType),  $id);
        }
    }
    private function getSingleUser($user_id){
        return $this->d->getSingleUserData($user_id);
    }





    /*重新更改 结束*/
 

}


